#pragma once
#ifndef xLod_h__
#define xLod_h__
#include "xLodFrustumTerrain.h"
namespace Sky
{
	class xLod
	{
	public:
		typedef TUint16   (*tZX2Index)[PATCH_EDEG_VERTS_NUMB];
		typedef struct _tIndex2ZX_
		{
			TInt16 x;
			TInt16 z;
		}tIndex2ZX;
	private:
		xFrustum mFrustum;
		TInt	 m_LevelCount;
		ID3DXEffect*   m_peft;
		xLodFrustumTerrain m_terrains[LOD_LEVELS];
		TInt m_WorldCenterX,m_WorldCenterZ;
		//file map
		HANDLE m_hMapFile;
		HANDLE m_hMapView;
		TFloat* m_pMapPtr;
		TUint16  m_zx2index[PATCH_EDEG_VERTS_NUMB][PATCH_EDEG_VERTS_NUMB];
		tIndex2ZX m_index2zx[PATCH_EDEG_VERTS_NUMB*PATCH_EDEG_VERTS_NUMB];
	public:
		xLod();
		TBool Init();
		TVoid Uninit();
		TBool getVisible(TInt level);
		TVoid setVisible(TInt level,TBool bShow);

		TVoid LoadTerrain(TInt x = 0,TInt z = 0);
		tZX2Index	getXZ2Index();
		tIndex2ZX*  getIndex2XZ(){return m_index2zx;}
		TResult	onCameraMove(xGPCamera* camera);
		TVoid   saveCurrent();
		TVoid	loadCurrent();
		TVoid	updateCurrent();
		
		TResult onCreate(xDevice* dev);
		TResult	onDelete(xDevice* dev);
		TResult onRender(xDevice* dev,xGPCamera* camera);
		TVoid	setSizeCanSee(TInt size);
		TInt	getLevelCount(){return m_LevelCount;}
		xLodFrustumTerrain* getLevelTerrain(TInt level);
	};
}

#endif // xLod_h__